$(function(){
    showDrugList();
});

function showDrugList(){
    API.table_get('pharmacy_cate_drug',{pharmacy:getParam('pharmacy'),p:getParam('p'),cid:getParam('cid')},doCateShowDrug);
}

function doCateShowDrug(table_name,msg,getStatus){
    console.log(msg);
    if(getStatus){
        table_obj = $('#drug_table');
        //对相应的数据进行展示
        if(msg.length == 0){
            getNoneReplay();
            return false;
        }else{
            $('#has_no_msg').parent().empty();
            for(var i=0 ;i<msg.drug_list.length;i++){
                temp = msg.drug_list[i];
                tr = '<tr>';
                tr += '<td><img src="' + ((temp.drug_base_info.images.thumb[0].indexOf('http://'))?IMG_PREFIX+temp.drug_base_info.images.thumb[0]:temp.drug_base_info.images.thumb[0]) + '"onclick="showBigPic($(this))" width="40px" height="40px" /></td>';
                tr += '<td>' + msg.cname + '</td>';
                tr += '<td>' + temp.drug_base_info.product_name + '</td>';
                tr += '<td>' + temp.drug_base_info.instructions.生产企业 + '</td>';
                tr += '<td>' + temp.drug_base_info.drug_form + '</td>';
                tr += '<td>' + getStatusShow(temp.is_recommend) + '</td>';
                tr += '<td>' + getStatusShow(temp.is_sale) + '</td>';
                tr += '<td>' + getStatusShow(temp.unsold) + '</td>';
                tr += '<td>' + temp.price + '</td>';
                tr += '<td>' + temp.sale_price + '</td>';
                tr += '</tr>';
                table_obj.append(tr);
            }
        }
        //分页
        $('#page').createPage({
            pageCount:Math.ceil(msg.drug_count/20),
            current:parseInt(getParam('p')),
            backFn: function (p) {
                console.log(p);
                window.location.href = window.location.href.replace('p='+getParam('p'),'p='+p);
            }
        })
    }else{
        getNoneReplay();
    }

}
